package com.xiaoq.users.emchat.endpoint;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiaoq.users.emchat.service.EasemobChatGroupService;


/**
 * @author xinpeng created on 2016/11/30-下午4:46.
 */
@RestController
@RequestMapping(value = "/api/v1/user/chat")
class EasemobChatGroupEndpoint {

    private static final Logger logger = LoggerFactory.getLogger(EasemobChatGroupEndpoint.class);

    @Autowired
    EasemobChatGroupService easemobChatGroupService;


    @RequestMapping(value = "/chat_groups", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.POST)
    public ResponseEntity<String> createChatGroup4Activity(
            HttpServletRequest request,
            @RequestParam String groupName,
            @RequestParam String organizerIdOfActivity,
            @RequestParam long maxusersOfActivity){


        /** 创建群组
         * curl示例
         * curl -X POST 'https://a1.easemob.com/easemob-playground/test1/chatgroups' -H 'Authorization:
         * Bearer {token}' -d '{"groupname":"测试群组","desc":"测试群组","public":true,"approval":true,
         * "owner":"xiaojianguo001","maxusers":333,"members":["xiaojianguo002","xiaojianguo003"]}'
         */

        String groupId = easemobChatGroupService.createChatGroup(groupName,maxusersOfActivity,organizerIdOfActivity);

        return new ResponseEntity<>(groupId, HttpStatus.OK);
    }

}


